const Koa = require('koa')
const app = new Koa()
//引入connect
const mongoose = require('mongoose')
const { connect, initSchemas } = require('./database/init.js')

// 路由
const Router = require('koa-router')
const router = new Router()

const bodyParser = require('koa-bodyparser')

// 处理跨域
const cors = require('koa2-cors')

app.use(bodyParser())
app.use(cors())

let user = require('./api/user.js')
let goods = require('./api/goods.js')
let index = require('./api/index.js')
router.use('/user', user.routes())
router.use('/goods',goods.routes())
router.use('/index',index.routes())

app.use(router.routes()).use(router.allowedMethods())

;(async () =>{
  await connect()
  initSchemas()
})()

app.listen(3000, () => {
  console.log('server started on port 3000')
})